<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<meta name="author" content="SkyKiDS" />
		<meta name="keywords" content="계산기, calculator" />
		<meta name="description" content="계산기입니다." />
		<title>공학용 계산기, an extended calculator.</title>
		<style type="text/css">
		<!--
			img {border:0;}

			.panel {width:524px; height:20px; text-align:right; vertical-align:bottom; padding-right:5px; padding-top:5px;}
			.button {width:80px; height:50px;}
			.equal {width:100%; height:50px;}
			.blank {width:30px; height:50px;}
		// -->
		</style>
		<script type="text/javascript">
		<!-- <![CDATA[
			function inputMethod(n, f) {
				var panel = document.getElementById("panel");

				if (f == true) {
					panel.value = n;
				}
				else {
					if (panel.value == "0") {
						if (n == ".") {
							panel.value += n;
						}
						else if (n == "00") {
							panel.value = "0";
						}
						else {
							panel.value = n;
						}
					}
					else {
						panel.value += n;
					}
				}
			}

			function calculation() {
				var panel = document.getElementById("panel");

				try
				{
					panel.value = eval(panel.value);
				}
				catch (e)
				{
					alert("수식이 올바르지 않습니다.");
				}
				finally
				{
				}
			}

			function calFunction(func, hasData) {
				var panel = document.getElementById("panel");

				if (hasData == false) {
					if (func == "Formula") {
						storedValue = prompt("수식을 입력하세요. 수식을 입력하기 전의 내용은 지워집니다.", 0);

						try
						{
							panel.value = eval(storedValue);
						}
						catch (e)
						{
							alert("수식이 올바르지 않습니다.");
						}
						finally
						{
						}
					}
					else if (func == "Backspace") {
						if (panel.value.length <= 1) {
							panel.value = 0;
						}
						else {
							panel.value = panel.value.substring(0, (panel.value.length -1));
						}
					}
					else {
					}
				}
				else {
					try
					{
						var storedValue = eval(panel.value);
					}
					catch (e)
					{
						alert("수식이 올바르지 않습니다.");
						return false;
					}
					finally
					{
					}

					if (func == "Int") {
						if (typeof storedValue != "number") {
							alert("숫자가 아닙니다.");
						}
						else {
							panel.value = parseInt(storedValue);
						}
					}
					else if (func == "n!") {
						if ((typeof storedValue != "number") || (storedValue % 1 != 0)) {
							alert("정수값이 아닙니다.");
						}
						else {
							for (var i = storedValue - 1; i > 0; i--) {
								storedValue = storedValue * i;
							}
							panel.value = storedValue;
						}
					}
					else {
					}
				}
			}
		// ]]> -->
		</script>
	</head>
	<body>
<!-- 
accesskeys list
0~9 : 0~9
. : .
+, -, *, / : +, -, *, /
(, ) : ( )
i : Int
r : Rand
f : n!
p : pi
o : Formula
// -->
<div id="wrapper">
	<form id="calForm" action="" method="post">
	<table style="border:1px solid black; padding:5px;">
		<tr>
			<td colspan="7"><input id="panel" type="text" class="panel" value="0" readonly="readonly" /></td>
		</tr>
		<tr>
			<td><input type="button" class="button" value="7" onclick="inputMethod(this.value);" accesskey="7" /></td>
			<td><input type="button" class="button" value="8" onclick="inputMethod(this.value);" accesskey="8" /></td>
			<td><input type="button" class="button" value="9" onclick="inputMethod(this.value);" accesskey="9" /></td>
			<td><input type="button" class="button" value="+" onclick="inputMethod(this.value);" accesskey="+" /></td>
			<td class="blank"></td>
			<td><input type="button" class="button" value="Formula" onclick="calFunction(this.value, false);" accesskey="o" /></td>
			<td><input type="button" class="button" value="Backspace" onclick="calFunction(this.value, false);" accesskey="p" /></td>
			<td><input id="clear" type="reset" class="button" value="C" accesskey="c" /></td>
		</tr>
		<tr>
			<td><input type="button" class="button" value="4" onclick="inputMethod(this.value);" accesskey="4" /></td>
			<td><input type="button" class="button" value="5" onclick="inputMethod(this.value);" accesskey="5" /></td>
			<td><input type="button" class="button" value="6" onclick="inputMethod(this.value);" accesskey="6" /></td>
			<td><input type="button" class="button" value="-" onclick="inputMethod(this.value);" accesskey="-" /></td>
			<td class="blank"></td>
			<td><input type="button" class="button" value="(" onclick="inputMethod(this.value);" accesskey="(" /></td>
			<td><input type="button" class="button" value=")" onclick="inputMethod(this.value);" accesskey=")" /></td>
			<td><input type="button" class="button" value="Rand" onclick="inputMethod(Math.random(), true);" accesskey="r" /></td>
		</tr>
		<tr>
			<td><input type="button" class="button" value="1" onclick="inputMethod(this.value);" accesskey="1" /></td>
			<td><input type="button" class="button" value="2" onclick="inputMethod(this.value);" accesskey="2" /></td>
			<td><input type="button" class="button" value="3" onclick="inputMethod(this.value);" accesskey="3" /></td>
			<td><input type="button" class="button" value="*" onclick="inputMethod(this.value);" accesskey="*" /></td>
			<td class="blank"></td>
			<td><input type="button" class="button" value="Int" onclick="calFunction(this.value);" accesskey="i" /></td>
			<td><input type="button" class="button" value="n!" onclick="calFunction(this.value);" accesskey="f" /></td>
				<td><input type="button" class="button" value="pi" onclick="inputMethod(Math.PI, true);" accesskey="p" /></td>
		</tr>
		<tr>
			<td><input type="button" class="button" value="0" onclick="inputMethod(this.value);" accesskey="0" /></td>
			<td><input type="button" class="button" value="00" onclick="inputMethod(this.value);" /></td>
			<td><input type="button" class="button" value="." onclick="inputMethod(this.value);" accesskey="." /></td>
			<td><input type="button" class="button" value="/" onclick="inputMethod(this.value);" accesskey="/" /></td>
			<td class="blank"></td>
			<td colspan="4"><input id="equal" type="button" class="equal" value="=" onclick="calculation();" accesskey="=" /></td>
		</tr>
	</table>
	</form>
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a></p>
</div>
	</body>
</html>